import express from "express";
import cors from "cors";
import customerRouter from "./router/customer.js";
import { PrismaClient } from "@prisma/client";

const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));


// 实例化prisma客户端
const db = new PrismaClient();
// 配置中间件
app.use((req, res, next) => {
  req.db = db;
  res.success = (data, info) => {
    res.send({ success: true, data, info });
  };
  res.fail = (info) => {
    res.send({ success: false, info });
  };
  next();
});

// 路由
app.use(customerRouter);

app.listen(3000, () => {
  console.log("app is running at port 3000");
});
